/*
 * Copyright 2011 Angel Sanadinov
 *
 * This file is part of VBox WMI.
 *
 * VBox WMI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VBox WMI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
 */

package Beans.Requests.UserManagement;

import Utilities.PermissionsConstants;

/**
 * Instances of this class are used by the user interface when a request to modify
 * a user is sent to the users management service(s).
 *
 * @author Angel Sanadinov
 */
public class UserModifyRequest extends UserManagementRequest
{
    private int accountLevel;           //user account level
    private boolean isAccountLevelSet;  //determines whether the account lvl was set

    /**
     * No-argument constructor. <br><br>
     * Only the requested action is set (modify).
     */
    public UserModifyRequest()
    {
        super.setRequestedAction(PermissionsConstants.ACTION_USER_MODIFY);
    }

    /**
     * Constructs the request object using the supplied data for user modification.
     *
     * <b>Note:</b> <i>Specific modifications need to be set using the appropriate
     *              methods.</i>
     *
     * @param requestorId the id the of the user that requested the action
     * @param affectedUserId the id of the affected user
     */
    public UserModifyRequest(int requestorId, int affectedUserId)
    {
        super.setRequestorId(requestorId);
        super.setAffectedUserId(affectedUserId);
        super.setRequestedAction(PermissionsConstants.ACTION_USER_MODIFY);
    }

    /**
     * Returns whether the user account level was set.
     *
     * @return <code>true</code> if the account level was set or <code>false</code>
     *         otherwise
     */
    public boolean isAccountLevelSet()
    {
        return isAccountLevelSet;
    }

    /**
     * Retrieves the user's account level.
     *
     * @return the user account level
     */
    public int getAccountLevel()
    {
        return accountLevel;
    }

    /**
     * Sets the user's account level.
     *
     * @param accountLevel the account level of the user
     */
    public void setAccountLevel(int accountLevel)
    {
        this.accountLevel = accountLevel;
        this.isAccountLevelSet = true;
    }

    /**
     * Checks the validity of the object. <br><br>
     *
     * This object is valid only when all data required for the request is valid.
     *
     * @return <code>true</code> if the object is valid or <code>false</code> otherwise
     */
    @Override
    public boolean isValid()
    {
        //both requestor and affected user ids need to be valid along with at least one modification
        if(isAffectedUserIdValid() && isRequestorIdValid())
            return true;
        else
            return false;
    }

    /**
     * Returns a textual representation of the object. <br>
     *
     * It is in the form: "ClassName: (affectedUserId,accountLevel)".
     *
     * @return the object represented as a String
     */
    @Override
    public String toString()
    {
        return UserModifyRequest.class.getSimpleName() + ": (" + getAffectedUserId()
                + "," + accountLevel + ")";
    }
}
